Compass 5 Click
Compass 5 Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.
Click Library
- Author : Jelena Milosavljevic
- Date : Jul 2021.
- Type : I2C type
Software Support
Example Description
This is an example that demonstrates the use of Compass 5 Click board that reads data from magnetic sensors for X, Y, and Z axes,processes it and displays it via the UART terminal.
Example Libraries
- MikroSDK.Board
- MikroSDK.Log
- Click.Compass5
Example Key Functions
- compass5_cfg_setup Config Object Initialization function.
void compass5_cfg_setup(compass5_cfg_t *cfg)
Compass 5 configuration object setup function.
Compass 5 Click configuration object.
Definition compass5.h:212
- compass5_init Initialization function.
err_t compass5_init(compass5_t *ctx, compass5_cfg_t *cfg)
Compass 5 initialization function.
Compass 5 Click context object.
Definition compass5.h:198
- compass5_write_byte This function writes a desired number of data bytes starting from the selected register by using I2C serial interface.
void compass5_write_byte(compass5_t *ctx, uint8_t reg, uint8_t tx_data)
Compass 5 write byte function.
- compass5_read_byte This function read 1 byte.
uint8_t compass5_read_byte(compass5_t *ctx, uint8_t reg)
Compass 5 read 1 byte function.
- compass5_sw_reset This function for software reset.
void compass5_sw_reset(compass5_t *ctx)
Compass 5 software reset function.
Application Init
Initializes I2C and starts to write log, performs power down mode, sets continuous measurement mode; also write log.
{
log_cfg_t log_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
Delay_ms ( 100 );
if ( I2C_MASTER_ERROR == init_flag ) {
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
Delay_ms ( 500 );
log_printf( &logger, "--------------------\r\n" );
log_printf( &logger, " Compass 3 Click \r\n" );
log_printf( &logger, "--------------------\r\n" );
}
else {
log_printf( &logger, " Fatal error!!! \r\n" );
for ( ; ; );
}
Delay_ms ( 100 );
log_printf( &logger, " Power Down Mode \r\n" );
log_printf( &logger, "-------------------\r\n" );
Delay_ms ( 100 );
log_printf( &logger, " Continuous \r\n" );
log_printf( &logger, " Measurement Mode \r\n" );
log_printf( &logger, "-------------------\r\n" );
Delay_ms ( 100 );
log_printf( &logger, " Start Measurement \r\n" );
log_printf( &logger, "-------------------\r\n" );
Delay_ms ( 100 );
log_info( &logger, " Application Task " );
}
#define COMPASS5_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition compass5.h:186
#define COMPASS5_COMPANI_ID_NUM
Definition compass5.h:79
#define COMPASS5_DEVICE_ID_NUM
Compass 5 description register.
Definition compass5.h:78
#define COMPASS5_MODE_CON_MEASUREMENT_100HZ
Definition compass5.h:138
#define COMPASS5_MODE_POWER_DOWN
Compass 5 description setting operation mode.
Definition compass5.h:133
void compass5_get_id(compass5_t *ctx, uint8_t *company_id, uint8_t *device_id)
Compass 5 get ID function.
uint8_t compass5_set_operation_mode(compass5_t *ctx, uint8_t op_mode)
Compass 5 set operation mode function.
void application_init(void)
Definition main.c:32
uint8_t company_id
Definition main.c:29
uint8_t device_id
Definition main.c:28
Application Task
When Compass 5 Click is connected to a mikroBUS, this example collects data on the current position of the X, Y and Z axes via I2C communication, processes and displays the data via the UART terminal. All axis data is printed every 2 seconds.
{
int16_t x_val;
int16_t y_val;
int16_t z_val;
Delay_ms ( 10 );
log_printf( &logger, " X-axis: %d mG\r\n", x_val );
log_printf( &logger, " Y-axis: %d mG\r\n", y_val );
log_printf( &logger, " Z-axis: %d mG\r\n", z_val );
log_printf( &logger, "--------------------\r\n" );
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
#define COMPASS5_DATA_READY
Definition compass5.h:155
void compass5_measurement_axis(compass5_t *ctx, int16_t *axis_x, int16_t *axis_y, int16_t *axis_z)
Compass 5 full measurement axis function.
uint8_t compass5_check_data_ready(compass5_t *ctx)
Compass 5 check data ready function.
void application_task(void)
Definition main.c:93
Application Output
This Click board can be interfaced and monitored in two ways:
- Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
- UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.
Additional Notes and Information
The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.